<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页 - 宠物寄养平台-后台管理系统</title>
<jsp:include page="headlink.jsp"></jsp:include>
</head>

<body>
	<div class="lyear-layout-web">
		<div class="lyear-layout-container">
			<!--左侧导航-->
			<jsp:include page="leftsidebar.jsp"></jsp:include>
			<!--End 左侧导航-->

			<!--头部信息-->
			<jsp:include page="header.jsp"></jsp:include>
			<!--End 头部信息-->

			<!--页面主要内容-->
			<main class="lyear-layout-content">

			<div class="container-fluid">

				<div class="demoTable">
					搜索姓名：
					<div class="layui-inline">
						<input class="layui-input" name="id" id="demoReload"
							autocomplete="off">
					</div>
					<button class="layui-btn" data-type="reload">搜索</button>
				</div>
				<table class="layui-hide" id="test" lay-filter="test"></table>


			</div>

			</main>
			<!--End 页面主要内容-->
		</div>
	</div>

	<script type="text/javascript" src="${pageContext.request.contextPath}/backmanage/js/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/backmanage/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/backmanage/js/perfect-scrollbar.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/backmanage/js/main.min.js"></script>
	<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
    <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
	
  </div>
</script>

	<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath}/backmanage/layui/layui.js" charset="utf-8"></script>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

	<script>
		layui.use('table', function() {
			var table = layui.table;
			var form = layui.form;

			table.render({
				elem : '#test',
				url : '../page',
				toolbar : '#toolbarDemo',
				title : '媒体资源数据表',
				cols : [ [ {
					type : 'checkbox',
					fixed : 'left'
				}, {
					field : 'mid',
					title : '媒体资源编号',
					width : 120,
					sort : true,
					fixed : 'left'
				}, {
					field : 'mtype',
					title : '资源类型',
					width : 120,
					templet : function(res) {
						return res.mtype == 1 ? "图片" : "视频"
					}
				}, {
					field : 'msaveurl',
					title : '资源存储地址',
					width : 280,
					sort : true
				}, {
					field : 'ofuname',
					title : '上传人',
					width : 180,
					templet : function(res) {
						return res.orders.ofuname;
					}
				}, {
					fixed : 'right',
					title : '操作',
					toolbar : '#barDemo',
					width : 150
				} ] ],
				page : true,
				id : 'testReload'
			});

			//头工具栏事件
			table.on('toolbar(test)', function(obj) {
				var checkStatus = table.checkStatus(obj.config.id);
				switch (obj.event) {
				case 'getCheckData':
					var data = checkStatus.data;
					layer.alert(JSON.stringify(data));
					break;
				case 'getCheckLength':
					var data = checkStatus.data;
					layer.msg('选中了：' + data.length + ' 个');
					break;
				case 'isAll':
					layer.msg(checkStatus.isAll ? '全选' : '未全选');
					break;

				}
				;
			});

			//监听行工具事件
			table.on('tool(test)', function(obj) {
				var data = obj.data;
				var mid = data.mid;
				var mtype = data.mtype;
				var msaveurl = data.msaveurl;
				var ofuname = data.ofuname;

				if (obj.event === 'del') {
					layer.confirm('真的删除吗？', function(index) {
						$.ajax({
							'type' : 'DELETE',
							'url' : '../del/' + mid,
							'success' : function(data) {
								layer.msg(data.msg, {
									time : 2000
								//两秒延迟
								}, function() {
									if (data.msg == "删除成功") {

										//obj.update(); ?? 理想
										//layer.close(index);;
										parent.layer.closeAll();//关闭所有,简单粗暴
										window.parent.location.reload();//刷新父页面

									}
								});
							}
						});
					})

				}
			});

			var $ = layui.$, active = {
				reload : function() {
					var demoReload = $('#demoReload');

					//执行重载
					table.reload('testReload', {
						page : {
							curr : 1
						//重新从第 1 页开始
						},
						where : {
							content : demoReload.val()
						}
					});
				}
			};

			$('.demoTable .layui-btn').on('click', function() {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});

		});
	</script>

</body>